<?php
    include_once '../../../../controlador/php/conexion/Conexion10.php';
    $con = new Conexion10();
    
    $ingreso= $_REQUEST['ingreso'];
    
    $listado = "select ADNINGRESO.AINCONSEC as 'ingreso', HCNFOLIO.HCNUMFOL as 'numfolio', GENPACIEN.PACNUMDOC as 'documento',  RTrim(GENPACIEN.PACPRINOM) + ' ' +
                   RTrim(GENPACIEN.PACSEGNOM) + ' ' + RTrim(GENPACIEN.PACPRIAPE) + ' ' +
                   RTrim(GENPACIEN.PACSEGAPE) As 'paciente', GENMEDICO.GMENOMCOM as 'medico',
                   convert(nvarchar(2000),HCCM02N31) as 'Cama_solicitud', HPNDEFCAM.HCACODIGO as 'cama_facturacion',
                   gasnombre as 'area_de_servicio',
                   case when HCCM07N29	IS null then 'No'else 'Si' end as 'Reserva',
                   HCFECFOL as FECHA_SOLICITUD
                   from GENPACIEN
                   inner join HCNFOLIO on HCNFOLIO.GENPACIEN = GENPACIEN.oid
                   inner join HCMTRANSF on HCMTRANSF.HCNFOLIO = HCNFOLIO.oid
                   INNER JOIN ADNINGRESO ON HCNFOLIO.ADNINGRESO=ADNINGRESO.oid
                   INNER JOIN GENMEDICO ON HCNFOLIO.GENMEDICO = GENMEDICO.OID
                   left outer join GENARESER on HCMTRANSF.HCCM22N33 = GENARESER.oid
                   LEFT OUTER JOIN HPNESTANC ON ADNINGRESO.OID= HPNESTANC.ADNINGRES   AND HPNESTANC.HESFECSAL IS NULL
                   LEFT OUTER JOIN HPNDEFCAM ON HPNESTANC.HPNDEFCAM=HPNDEFCAM.OID
                   where ADNINGRESO.AINCONSEC='".$ingreso."'
                   order by FECHA_SOLICITUD desc";
    $res = $con->query($listado);
   
    while($re = mssql_fetch_array($res)){
        $lista[] = array_map(utf8_encode,$re);
    }
    echo json_encode($lista);
    
    $con->cerrarConexion();
    
?>